import qiniu


def storage(data):
    if not data:
        return None
    access_key = '1PHFMgGOpIV7D_7UaZFz0LOYgJoFWWKV6Y8Et8l8'
    secret_key = 'RiCvLlpypkJv8hizfGhluZmz8Txlzb3iDqE8YTlv'
    q = qiniu.Auth(access_key, secret_key)

    # 空间名
    token = q.upload_token('python')
    ret, info = qiniu.put_data(token, None, data)
    print(info)
    if info.status_code != 200:
        raise Exception('七牛云失败')
    return ret['key']


if __name__ == '__main__':
    file = input('输入要上传的图片地址')
    with open(file, 'rb') as f:
        storage(f.read())
